﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
/// <summary>
/// 玩家脚本
/// 1.使用事件发布碰撞信息。观察者模式
/// 2.在Awake中重写，tag="Player",hasSlider=fals;···
/// </summary>
public class Player : Entity {
    public FuncListener<Collision> collisionEnter;//监听碰撞事件
    private Transform selfTransform;
    private bool IsNotDeath = true;
    private ObtainMusic om;
    MoveControl mCo;//获取动画机


    public override void GetDamage(Damage d)
    {
        base.GetDamage(d);
    }
    public Player()
    {
        hp = 4;
        hpLimit = 4;//主角的血量
    }
    protected override void Awake()
    {
        base.Awake();
        tag = "Player";//主角tag为Player，区别对待
          selfTransform = transform;
        mCo = GetComponent<MoveControl>();
        
    }
    private void OnCollisionEnter(Collision collision)
    {
       // print(collision.collider.tag);
        if (collisionEnter!=null)//发布信息
        {
        // print(collisionEnter == null);
#if DEBUGf
           if (collision.collider.tag==GameManager.TRIGGEROBJ)
            {
                print("player collision trigger");
            }
#endif
            collisionEnter(collision);
        }
    }
    public override void Death()
    {
        base.Death();
        GameManager.Instance.DeathPanel();

    }

    public void Update()
    {
        if (selfTransform.position.z >= 20f&&IsNotDeath)
        {
            IsNotDeath = false;
            Hp = 0;
        }
    }


}
